package com.gylang.crypto.crypto;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * aes 加解密
 * @author gylang
 * data 2020/10/27
 * @version v0.0.1
 */
@Component
@Slf4j
public class AesStrategy implements CryptoStrategy {


    @Override
    public String decrypt(String key, String content) {
        // 随机生成密钥
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key));
        return aes.decryptStr(content);
    }

    @Override
    public String encrypt(String key, String content) {
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key.getBytes(StandardCharsets.UTF_8));
        return aes.encryptBase64(content);
    }

    @Override
    public String sign(String key, String content) {
        return null;
    }

    @Override
    public boolean answer(String key, String content) {
        return true;
    }


}
